#include <bits/stdc++.h>
#define MAX 3003
#define ull unsigned long long
using namespace std;
short n, m;
char s[MAX][MAX];
short r[26][MAX][MAX], d[26][MAX][MAX];
ull ans;
inline int cti(char in)
{
    return in - 'a';
}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // freopen("ex_star4.in", "r", stdin);
    freopen("star.in", "r", stdin);
    freopen("star.out", "w", stdout);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int f = 1; f <= m; f++)
            cin >> s[f][i],
                r[cti(s[f][i])][f][i] = r[cti(s[f][i])][f - 1][i] + 1,
                d[cti(s[f][i])][f][i] = d[cti(s[f][i])][f][i - 1] + 1;
    for (short tp = 0; tp < 26; tp++)
    {
        for (short y = n; y > 1; y--)
            for (short x = m; x > 1; x--)
            {
                if (cti(s[x][y]) != tp)
                    continue;
                for (short i = y - 1; d[tp][x][i]; i--)
                    for (short f = x - 1; r[tp][f][i] && r[tp][f][y]; f--)
                        if ((d[tp][f][y] > y - i) && (r[tp][x][i] > x - f))
                            ans++;
            }
    }
    cout << ans;
}